package com.gy.hsim.bservice.asyncload;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import com.gy.hsim.bservice.framework.bean.GYMqEntity;
import com.gy.hsim.bservice.framework.common.generator.GuidGenUtil;
import com.gy.hsim.bservice.framework.db.ConnectionFactory;

public class AsyncDataDao {
	
	private final static String INSERT_SQL = "insert into T_CHAT_RECORD ( ID,FROM_UID, TO_UID,MSG_CONTENT, MSG_TIME, OPERATE_TIME,DEL_FLAG) values (?,?,?,?,?,NOW(),1)";

	
	
	public static boolean batchInsert(List<GYMqEntity>  list) {
		
		boolean result = false;
		
		/** 获取数据库连接 */
		Connection con = ConnectionFactory.getConnection();
		
		PreparedStatement ps = null;
		
		/** 初始化预处理Statement对象 */
		try {
			ps = con.prepareStatement(INSERT_SQL);
			
			for(int i = 0; i < list.size(); i++)  
	        {  
				GYMqEntity entity = list.get(i);  
	            ps.setLong(1, GuidGenUtil.getLongGuid());
				ps.setString(2, entity.getFromUid());
				ps.setString(3, entity.getToUid());
				ps.setString(4, entity.getMessage());
				ps.setLong(5, Long.parseLong(new SimpleDateFormat(
						"yyyyMMddHHmmss").format(entity.getDateTime())));
				ps.addBatch();
	        }  
			
			ps.executeBatch();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		
		
		return result;
	}

}
